package com.x.kafka.impl;

import com.x.kafka.MqTemplate;
import org.springframework.kafka.core.KafkaTemplate;

public class MqKafkaTemplate implements MqTemplate {

    private final KafkaTemplate<String, Object> kafkaTemplate;
    private Boolean enable;

    public MqKafkaTemplate(KafkaTemplate<String, Object> kafkaTemplate, Boolean enable){
        this.kafkaTemplate = kafkaTemplate;
        this.enable = enable;
    }

    @Override
    public <T> void send(String topic, String key, T data) {
        if (!enable){
            return;
        }
        this.kafkaTemplate.send(topic, key, data);
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }
}
